<template>
	<view class="content">
		<view @click='forceJump1'> 强制跳转1 </view>
		<view @click='forceJump2'> 强制跳转2 </view>
		
	    <myTab 
			ref="myTab"
			:scrollIndex="scrollIndex"
	        v-model="activeKey" 
	        :navData="scrollData"
	        @change="tabChange"
	        @tabClick="tabClick"
	    >
	        <view :slot="item.slot" v-for="(item,key) in scrollData" :key="key">
	            <scroll-view scroll-y height="400rpx">
	                第{{scrollIndex}}页
					
					
					<view v-if="scrollIndex == 1">
						
						<view @click="junpToPortrait">点击跳转到[肖像照]页面</view>
						<interval-bar></interval-bar>
						
						<view @click="junpToPhoto">点击跳转到[拍照]页面</view>
						<interval-bar></interval-bar>
						
						<view @click="jumpToSign">点击跳转到[手写电子签名]页面</view>
						<interval-bar></interval-bar>
					
						<view  v-if="image">
							<image class="shancs" :src="image" mode=""></image>
							<interval-bar></interval-bar>
						</view>
						<view v-else>
							<interval-bar></interval-bar>
						</view>
						
						<view @click="register_title2">检测是否成功获取图片</view>
						<interval-bar></interval-bar>
						<view @click="deleteImage">清空图片</view>
					</view>
	            </scroll-view>
	        </view>
	    </myTab>
		
		
		
	</view>
	
	
</template>


<script>
	import intervalBar from "../../components/bdpicker/intervalBar.vue";
	import myTab from '@/components/Mark-Tab/Tab.vue';
	
	export default {
		components: {
			intervalBar,
			myTab,
		},
		data() {
			return {
				activeKey: 0,
				scrollIndex: 1,
				scrollData: [
					{
						label:'预报名',
						slot:'slot-1'
					},
					{
						label:'正式报名',
						slot:'slot-2'
					}
				],
				src: "",
				image: "",
				key_img_1: "image111",
				key_img_2: "image222",
				key_img_3: "image333",
			}
		},
		onLoad(option) {
			 //option可以接到index 传过来的值
			 console.log('onLoad option -------------- ', option);
			 this.option = option;
		 },
		onShow(){
			this.getValuesFromPrePage(['key_img_1'], [this.key_img_1]);
			console.log('~~~~~~~~~~~~ onShow! this.image123:', this.image123, this.api.getValuesFromPrePage(this.key_img_3));
			
			console.log('＊＊＊＊＊＊＊＊＊＊＊＊＊＊＊　this.image333: ', this.image333);
			this.register_title2();
			
			// // 3秒后返回上一页
			// setTimeout(function(){
			//                  uni.navigateBack({
			//                      delta: 1
			//                  })
			//              }, 3000);
			
		},
		methods: {
			forceJump1(){
				this.scrollIndex = 1;
				console.log(this.scrollIndex);
				// console.log('================== ', this.$refs.myTab);
				// this.$refs.myTab.testLog();
				// this.$refs.myTab.$refs.scrollNav.render(0);
				
			},
			forceJump2(){
				this.scrollIndex = 2;
				console.log(this.scrollIndex);
				// this.$refs.myTab.$refs.scrollNav.render(1);
				
				setTimeout(()=>this.forceJump1(), 500)
			},
			tabChange(e){
				console.log(e);
				this.scrollIndex = e.index + 1;
				console.log('scrollIndex', this.scrollIndex);
				// this.$refs.myTab.$refs.scrollNav.render(0);
				// this.scrollIndex = 1;
				setTimeout(()=>this.forceJump1(), 500)
			},
			tabClick(e){
				console.log(e);
			},
			
			jumpToSign() {
				// 测试[手写电子签名]
				uni.navigateTo({
					url: '../sign/sign?key=' + this.key_img_1
				})
			},
			junpToPortrait() {
				// 测试[肖像照]
				var url = '../scan-frame/portrait?key=' +　this.key_img_3
				uni.navigateTo({
					url: url
				})
			},
			junpToPhoto() {
				console.log('this.image1: ', this.image);
				
				// var url = '../scan-frame/scan-frame?photo_text=身份证反面(人像面)'
				var url = '../scan-frame/scan-frame'
				uni.navigateTo({
					url: url
				})
			},
			deleteImage() {
				this.image = "";
				uni.removeStorageSync('ceshiUrl');
				console.log('this.option', this.option);
			},
			register_title2() {
				/* 调用页面获取图片URL方法 */
				let pages = getCurrentPages();
				let currPage = pages[pages.length-1];
				// console.log(Object.keys(currPage.data));
				
				var image_sign_1 = currPage.data[this.key_img_1];
				var image_sign_2 = currPage.data[this.key_img_2];
				var image_sign_3 = currPage.data[this.key_img_3];
				console.log('image_sign_1', image_sign_1);
				console.log('image_sign_2', image_sign_2);
				console.log('image_sign_3', image_sign_3);
				if(typeof(image_sign_1) != undefined && image_sign_1 != null){
					console.log('成功获取图片image_sign_1：', image_sign_1)
					this.image = image_sign_1;
				};
				
				if(typeof(currPage.data.image) != undefined && currPage.data.image != null){
					// console.log('成功获取图片：', currPage.data.image)
					this.image = currPage.data.image;
				};
				if(this.image){
					console.log('this.image: ', this.image);
					// console.log('this._data.image: ', this._data.image);
				}
				else{
					console.log('this.image为空! 将检测电子签名!')
					
					var ceshiUrl = uni.getStorageSync('ceshiUrl');
					console.log('===== ceshiUrl: ', ceshiUrl);
					this.image = ceshiUrl;
					uni.removeStorage({
						key: 'ceshiUrl'
					})
				}
			}
		}
	}
</script>

